let express = require('express');
let router = express.Router();
let utils = require('./utils');
let requireAuth = utils.requireAuth;
let Goods = require("../model/goods");
let User = require("../model/user");

//发布信息
router.post('/new', requireAuth, (req, res) => {
    let goods = req.body.publishInfo;
    console.log(goods);

    User.findOne({openId: req.openid}, (err, user)=>{
        new Goods({
            name: goods.name,
            type: goods.type,
            address: goods.address,
            images: goods.images,
            userId: user._id,
        }).save(function(err, movie){
            if(err){
                console.log(err);
            }
        })        
    })

    res.json({
        message: 'publish success!'
    })
});

module.exports = router;